package osgiequinoxpluginproject;

import java.util.ArrayList;
import java.util.List;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import osgiequinoxpluginproject.impl.HelloImpl;

public class Activator implements BundleActivator
{
	private final List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	@Override
	public void start(final BundleContext context) throws Exception
	{
		System.out.println("Hello World!!");
		registrations.add(context.registerService(Hello.class.getName(), new HelloImpl("Hello, OSGi"), null));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	@Override
	public void stop(final BundleContext context) throws Exception
	{
		for (ServiceRegistration<?> registration : registrations)
		{
			System.out.println("unregistering:" + registration);
			registration.unregister();
		}
		System.out.println("Goodbye World!!");
	}

}
